<template>
	<view class="container">
		<block v-if="isload">
			<view class="form">
				<radio-group class="radio-group" @change="changeAccount" name="account">
					<view v-for="(item, index) in accountArr" class="form-item">
						<label class="radio">
							<radio :value="item.tel"></radio>{{item.tel}}
						</label>
					</view>
				</radio-group>
			</view>
			<button class="set-btn" @tap="formSubmit"
				:style="{background:'linear-gradient(90deg,'+t('color1')+' 0%,rgba('+t('color1rgb')+',0.8) 100%)'}">确
				定</button>
		</block>
		<loading v-if="loading"></loading>
		<dp-tabbar :opt="opt"></dp-tabbar>
		<popmsg ref="popmsg"></popmsg>
	</view>
</template>

<script>
	var app = getApp();

	export default {
		data() {
			return {
				opt: {},
				loading: false,
				isload: false,
				menuindex: -1,
				account: '',
				textset: {},
				haspwd: 0,
				accountArr:[
					{tel:'123123'},
					]
			};
		},

		onLoad: function(opt) {
			this.opt = app.getopts(opt);
			this.loaded();
			this.getChildAccount();
		},
		onPullDownRefresh: function() {
			//this.getdata();
		},
		methods: {
			changeAccount: function(e) {
				var that = this;
				var value = e.detail.value;
				that.account = value;
			},
			getChildAccount() {
				var that = this;
				app.post('ApiMy/childaccount', {},
					function(res) {
						if(res.status == 200){
							that.loading = false;
							that.accountArr = res.data;
						}else{
							app.error(res.msg);
						}
					});
			},
			formSubmit: function(e) {
				var formdata = e.detail.value;
				var account = this.account
				if (account == '') {
					app.alert('请选择子账号！');
					return;
				}
				app.showLoading('提交中');
				app.post("ApiMy/childchange", {
					tel: account
				}, function(data) {
					app.showLoading(false);
					if (data.status == 200) {
						app.success(data.msg);
						setTimeout(function() {
							app.goback(true);
						}, 1000);
					} else {
						app.error(data.msg);
					}
				});
			}
		}
	};
</script>
<style>
	.form {
		width: 94%;
		margin: 20rpx 3%;
		border-radius: 5px;
		padding: 20rpx 20rpx;
		padding: 0 3%;
		background: #FFF;
	}

	.form-item {
		display: flex;
		align-items: center;
		width: 100%;
		border-bottom: 1px #ededed solid;
		height: 98rpx;
		line-height: 98rpx;
	}

	.form-item:last-child {
		border: 0
	}

	.form-item .label {
		color: #000;
		width: 200rpx;
	}

	.form-item .input {
		flex: 1;
		color: #000;
	}

	.form-item .radio {
		height: 60rpx;
		line-height: 60rpx;
		color: #666;
		margin-right: 30rpx
	}

	.form-item .radio radio {
		transform: scale(0.8);
	}

	.set-btn {
		width: 90%;
		margin: 60rpx 5%;
		height: 96rpx;
		line-height: 96rpx;
		border-radius: 48rpx;
		color: #FFFFFF;
		font-weight: bold;
	}
</style>